package com.ws.client;

import java.util.List;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;

import com.ws.Cat;
import com.ws.Entry;
import com.ws.IHelloWorld;
import com.ws.StringCat;
import com.ws.User;
import com.ws.impl.HelloWorldWsService;
import com.ws.interceptor.LoginInterceptor;

public class ClientMain {
	public static void main(String[] args) {
		HelloWorldWsService factory = new HelloWorldWsService();
		IHelloWorld hw = factory.getHelloWorldWsPort();
		Client client = ClientProxy.getClient(hw);
		//添加out拦截器
		client.getOutInterceptors().add(new LoginInterceptor("admin", "123456"));
		client.getOutInterceptors().add(new LoggingOutInterceptor());
		//添加in拦截器
		client.getInInterceptors().add(new LoggingInInterceptor());
		
		
		
		System.out.println(hw.sayHi("孙悟空"));

		User user = new User();
		user.setId(3);
		user.setName("sun");
		user.setPass("3322");
		List<Cat> cats = hw.getCatsByUser(user);
		for (Cat cat : cats) {
			System.out.println(cat.getName());
		}

		StringCat allCats = hw.getAllCats();
		List<Entry> entries = allCats.getEntries();
		for (Entry entry : entries) {
			System.out.println(entry.getKey() + ":" + entry.getValue().getName());
		}

	}
}
